import Cookies from 'js-cookie'
const TokenKey = 'token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function setBtnRights(btnRights){
  return Cookies.set('btnRights', btnRights)
}

export function getBtnRights(){
  return Cookies.get('btnRights')
}

// 判断是否有权限
export function checkBtnAuth(route_path){
  // 转Json数据
  var btn_rights = JSON.parse(getBtnRights())
  var has_rights = false;
  btn_rights.forEach(element => {
    if(element.post_url === route_path){
      has_rights = true
      return 
    }
  });
  return has_rights
}
